1 // Copyright 2012 The Apache Software Foundation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package org.apache.tapestry5.internal.services.compatibility;
16
17 import org.apache.tapestry5.services.compatibility.Compatibility;
18 import org.apache.tapestry5.services.compatibility.Trait;
19
20 import java.util.EnumSet;
21 import java.util.Map;
22
23 public class CompatibilityImpl implements Compatibility
24 {
25 private final EnumSet<Trait> traits;
26
27 public CompatibilityImpl(Map<Trait, Boolean> configuration)
28 {
29 // Since the default in 5.4 is true, we can just remove those for which the value is false.
30
31 traits = EnumSet.allOf(Trait.class);
32
33 for (Map.Entry<Trait, Boolean> entry : configuration.entrySet())
34 {
35 if (entry.getValue().equals(Boolean.FALSE))
36 {
37 traits.remove(entry.getKey());
38 }
39 }
40 }
41
42 public boolean enabled(Trait trait)
43 {
44 assert trait != null;
45
46 return traits.contains(trait);
47 }
48 }